package com.vitabuybuy.tv.ui.mine.order.after.adapter

import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.adaptebinding.ImageAdapter
import com.vitabuybuy.tv.databinding.ItemNegotiationHistoryBinding
import com.vitabuybuy.tv.dto.NegotiationDto
import com.library.common.base.BindRecycAdapter

class NegotiationHistoryAdapter :
    BindRecycAdapter<ItemNegotiationHistoryBinding, NegotiationDto>() {
    override fun onBindViewHolder(
        mBinding: ItemNegotiationHistoryBinding,
        itemData: NegotiationDto,
        holder: RecyclerView.ViewHolder,
        position: Int
    ) {
        when (itemData.status) {
            "待审核" -> {
                mBinding.clShopLayout.visibility = View.GONE
                mBinding.clUserLayout.visibility = View.VISIBLE
                mBinding.tvLogisticsNumber.visibility = View.GONE
                mBinding.tvLogisticsCompany.visibility = View.GONE
                ImageAdapter.setCircleImageUrl(
                    mBinding.ivUserAvatar,
                    itemData.account.avatar,
                    ContextCompat.getDrawable(mContext, R.drawable.wode_icon_touxiang)
                )
                mBinding.tvUserName.text = itemData.account.nickname
                mBinding.tvUserTime.text = itemData.createTime
                mBinding.tvUserContent.text = itemData.content
                mBinding.tvUserRefuseType.text = "退款类型：".plus(itemData.issue.type)
                mBinding.tvUserRefuseAmount.text = "退款金额：".plus(
                    String.format(
                        mContext.getString(R.string.price_with_value),
                        itemData.issue.amount
                    )
                )
                mBinding.tvUserRefuseReson.text = "退款原因：".plus(itemData.issue.reason)
                mBinding.tvUserRefuseDesc.text = "退款描述：".plus(itemData.issue.buyerDescription)
            }
            "待买家处理" -> {
                mBinding.clShopLayout.visibility = View.VISIBLE
                mBinding.clUserLayout.visibility = View.GONE
                mBinding.tvShopRefuseDesc.visibility = View.GONE
                ImageAdapter.setCircleImageUrl(
                    mBinding.ivShopAvatar,
                    itemData.store.logo,
                    ContextCompat.getDrawable(mContext, R.drawable.wode_icon_touxiang)
                )
                mBinding.tvShopName.text = itemData.store.name
                mBinding.tvShopTime.text = itemData.createTime
                mBinding.tvShopContent.text = itemData.content
                mBinding.tvShouJianRen.text = "收件人：".plus(itemData.issue.recipientName)
                mBinding.tvTuiHuoAdd.text = "退货地址：".plus(itemData.issue.refundAddress)
                mBinding.tvShopRefuseReson.text = "退货说明：".plus(itemData.issue.type)
            }
            "待卖家处理" -> {
                mBinding.clShopLayout.visibility = View.GONE
                mBinding.clUserLayout.visibility = View.VISIBLE
                mBinding.tvLogisticsNumber.visibility = View.VISIBLE
                mBinding.tvLogisticsCompany.visibility = View.VISIBLE
                mBinding.tvUserRefuseType.visibility = View.GONE
                mBinding.tvUserRefuseAmount.visibility = View.GONE
                mBinding.tvUserRefuseReson.visibility = View.GONE
                mBinding.tvUserRefuseDesc.visibility = View.GONE
                ImageAdapter.setCircleImageUrl(
                    mBinding.ivUserAvatar,
                    itemData.account.avatar,
                    ContextCompat.getDrawable(mContext, R.drawable.wode_icon_touxiang)
                )
                mBinding.tvUserName.text = itemData.account.nickname
                mBinding.tvUserTime.text = itemData.createTime
                mBinding.tvUserContent.text = itemData.content
                mBinding.tvLogisticsNumber.text = "物流公司：".plus(itemData.issue.logisticsName)
                mBinding.tvLogisticsCompany.text = "退货单号：".plus(itemData.issue.logisticsNumber)
            }
            "售后成功" -> {
                mBinding.clShopLayout.visibility = View.VISIBLE
                mBinding.clUserLayout.visibility = View.GONE
                mBinding.tvShopRefuseDesc.visibility = View.VISIBLE
                ImageAdapter.setCircleImageUrl(
                    mBinding.ivShopAvatar,
                    itemData.store.logo,
                    ContextCompat.getDrawable(mContext, R.drawable.wode_icon_touxiang)
                )
                mBinding.tvShopName.text = itemData.store.name
                mBinding.tvShopTime.text = itemData.createTime
                mBinding.tvShopContent.text = itemData.content
                mBinding.tvShouJianRen.visibility = View.GONE
                mBinding.tvTuiHuoAdd.visibility = View.GONE
                mBinding.tvShopRefuseReson.visibility = View.GONE
                mBinding.tvShopRefuseDesc.text = itemData.issue.sellerDescription
            }
            "售后失败"->{
                mBinding.clShopLayout.visibility = View.VISIBLE
                mBinding.clUserLayout.visibility = View.GONE
                mBinding.tvShopRefuseDesc.visibility = View.VISIBLE
                ImageAdapter.setCircleImageUrl(
                    mBinding.ivShopAvatar,
                    itemData.store.logo,
                    ContextCompat.getDrawable(mContext, R.drawable.wode_icon_touxiang)
                )
                mBinding.tvShopName.text = itemData.store.name
                mBinding.tvShopTime.text = itemData.createTime
                mBinding.tvShopContent.text = itemData.content
                mBinding.tvShouJianRen.visibility = View.GONE
                mBinding.tvTuiHuoAdd.visibility = View.GONE
                mBinding.tvShopRefuseReson.visibility = View.GONE
                mBinding.tvShopRefuseDesc.text = itemData.issue.sellerDescription
            }
            else -> {//可能是撤销
                mBinding.clShopLayout.visibility = View.GONE
                mBinding.clUserLayout.visibility = View.VISIBLE
                mBinding.tvLogisticsNumber.visibility = View.GONE
                mBinding.tvLogisticsCompany.visibility = View.GONE
                ImageAdapter.setCircleImageUrl(
                    mBinding.ivUserAvatar,
                    itemData.account.avatar,
                    ContextCompat.getDrawable(mContext, R.drawable.wode_icon_touxiang)
                )
                mBinding.tvUserName.text = itemData.account.nickname
                mBinding.tvUserTime.text = itemData.createTime
                mBinding.tvUserContent.text = itemData.content
                mBinding.tvUserRefuseType.text = "退款类型：".plus(itemData.issue.type)
                mBinding.tvUserRefuseAmount.text = "退款金额：".plus(
                    String.format(
                        mContext.getString(R.string.price_with_value),
                        itemData.issue.amount
                    )
                )
                mBinding.tvUserRefuseReson.text = "退款原因：".plus(itemData.issue.reason)
                mBinding.tvUserRefuseDesc.text = "退款描述：".plus(itemData.issue.buyerDescription)
            }
        }
    }

    override fun normalViewId(viewType: Int): Int {
        return R.layout.item_negotiation_history
    }
}
